
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.*;

public class aux_program {
       
        private static boolean debug = true;
       
        public static void main(String args [])
        {
               
               
                if(args.length == 0)
                {// if you do nothing
                                if(debug  == true)
                                {
                                        System.out.println(args);                                      
                                }
                       
                                System.err.println("Error: Missing  Keywords");
                                return;
                       
                }
                else if(args.length == 1)
                {// if you miss key word
                        if(debug  == true)
                        {
                                System.out.println(args);                                      
                        }
                        System.err.println("Error: Missing filename");
                        return;
                       
                }
                
                
                else
                {// if it is fine
                        if(debug  == true)
                        {
                                System.out.println("Everthing is fine");        
                                System.out.println("Keyword :" + args[0]);
                                System.out.println("File name :" + args[1]);
                        }
                        try{
                        	  // Open the file that is the first 
                        	  // command line parameter
                        	 
                        	  FileInputStream fstream = new FileInputStream(args[1]);
                        	   
                        	  
                        	  // Get the object of DataInputStream
                        	  DataInputStream in = new DataInputStream(fstream);
                        	  BufferedReader br = new BufferedReader(new InputStreamReader(in));
                        	  String strLine = null;
                        	  //Read File Line By Line
                        	  
                        	  int file_count = 0;
                        	  int word_count = 0;
                        	  int total_file = 0;
                        	  
                        	  
                        	  while ((strLine = br.readLine()) != null)   {
                      		  	StringTokenizer stringTokenizer = new StringTokenizer(strLine);
                      		  	System.out.println("The total no. of tokens generated :  " + stringTokenizer.countTokens());
                      		  		while(stringTokenizer.hasMoreTokens()){
                      		  			String tmep = stringTokenizer.nextToken();
                      		  				if(tmep.equals("bob"))
                      		  				{
                      		  					word_count++;
                      		  					System.out.println("We are here now");
                      		  					System.out.println(tmep);
                      		  				}
                      	
                      		  				System.out.println(tmep);
                      		  				System.out.println("thet bob is "+ word_count);
                      		  		}
                        	  
                        	  
                        	  }
                        	  //Close the input stream
                        	  in.close();
                        	    }catch (Exception e){//Catch exception if any
                        	  System.err.println("Error: " + e.getMessage());
                        	  }
                       }
                
               
        }
}
